﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SPWebShell
{
    /// <summary>
    /// Provides an abstraction over key SharePoint web interactions to help in unit testing
    /// </summary>
    public interface ISPRepository
    {
        /// <summary>
        /// Max number of items to fetch in a batch
        /// </summary>
        int BatchSize { get; set; }
        /// <summary>
        /// Returns the URL of the container web from the full url of the document library. If the incoming URL is encoded then it will be decoded first.
        /// e.g. 
        ///     Input:http://server/sites/site1/doclib001/Forms/AllItems.aspx
        ///     output:http://server/sites/site1/
        /// </summary>
        /// <param name="fulldocliburl"></param>
        /// <returns></returns>
        string GetContainerWebFromDocLibUrl(string urlAbsoluteAnyItemInSite);

        //Not sure if we need this.
        /////// <summary>
        /////// Returns the name of the document library from the full URL to any item in the doc lib. This is not a perfect method.
        /////// Could be fooled by specifying top level site folders instead of document library
        ///////         
        /////// </summary>
        /////// <param name="fulldocliburl"></param>
        /////// <returns></returns>
        ////string GetDocLibNameFromDocLibUrl(string fulldocliburl);
        /// <summary>
        /// Gets all items with ID>=startid. This approach allows for fetching all items in batches
        /// and overcomes limitations imposed by throttling settings
        /// </summary>
        /// <param name="startid"></param>
        /// <returns></returns>
        SPDoclibItem[] GetAllItems(SPDoclibLocation doclib, int startid);
        SPDoclibItem[] GetAllItemsInFolder(SPDoclibLocation doclib, int startid, string rootfolder );
        /// <summary>
        /// Creates a folder at the specified document library
        /// </summary>
        /// <param name="weburl"></param>
        /// <param name="doclib"></param>
        /// <param name="folderName"></param>
        /// <returns></returns>
        SPDoclibItem CreateFolder(SPDoclibLocation doclibLocation, string folderName,string urlContainingFolders);
        /// <summary>
        /// When given a full URL to a document library.
        /// e.g. http://server/sites/siteA/doclib1/AllItems.aspx
        /// The return value would be the name of the document library doclib1 and the site where this document library belogs
        /// i.e. http://server/sites/siteA/
        /// </summary>
        /// <param name="fullUrlToDocumentLibrary"></param>
        /// <returns></returns>
        SPDoclibLocation ResolveDoclibUrlFromPageUrl(string fullUrlToDocumentLibrary);
        /// <summary>
        /// Uploads the specified file to the folderpath. e.g. /Resumes/
        /// </summary>
        /// <param name="filebytes"></param>
        /// <param name="doclibDestination"></param>
        /// <param name="fileName"></param>
        /// <param name="folder"></param>
        void UploadFile(byte[] filebytes, SPDoclibLocation doclibDestination, string fileName, string folderpath,string title);

        byte[] DownloadFile(string urlAbsolute);
        /// <summary>
        /// Sets the max retry counts in case of web exceptions
        /// </summary>
        int RetryCount { get; set; }
        SPReplicationResults Replicate(SPDoclibLocation source, SPDoclibLocation dest, bool overwrite);
        /// <summary>
        /// Returns meta-data about a list or a document library
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        entity.SPList GetList(SPDoclibLocation source);
        /// <summary>
        /// Returns items in a list beginning from the starting ID and upto maxitems. The internal field names 
        /// specified by viewfields are in addition to the core fields like ID, Modified, Created, Modified by, Created by
        /// </summary>
        /// <param name="list"></param>
        /// <param name="viewfields"></param>
        /// <returns></returns>
        entity.SPListItem[] GetListItems(SPDoclibLocation location, int startid, int maxitems, string[] viewfields, bool dump, string file);
        entity.SPListItem[] GetListItemsEx(
                SPDoclibLocation location, int maxitems, string[] viewfields,
                string caml, string viewname,bool utcDates, string folder, 
                bool includemandatorycolumns, bool isrecursive,bool dump, string file);

        entity.SPListItem GetListItem(SPDoclibLocation location, int startid, int maxitems, string[] viewfields, bool dump, string file);
        /// <summary>
        /// Uploads the specified file to the folderpath. e.g. /Resumes/ using the specified meta-data.
        /// </summary>
        /// <param name="filebytes"></param>
        /// <param name="doclibDestination"></param>
        /// <param name="fileName"></param>
        /// <param name="folderpath"></param>
        /// <param name="properties"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        SPDoclibItem UploadFile(byte[] filebytes,SPWebShell.entity.SPList listInfo , SPDoclibLocation doclibDestination, string fileName, string folderpath, string[] properties, object[] values);
        void UpdateMetaData(SPDoclibLocation list, int itemid, string[] properties, object[] values);
        entity.SPListItem CreateListItem(SPDoclibLocation list,  string[] properties, object[] values);

        entity.SPUser[] GetSiteUsers(string urlSite);
        entity.SPGroup[] GetSiteGroups(string urlSite);
        bool CheckinFile(string urlAbsolute, string comments, int checkintype);
        bool CheckinFile(SPDoclibLocation location, int spid, string comments, int checkintype);

        Guid PutAnyDocument(byte[] content, string p);

        entity.SPWeb[] GetWebs(string p);

        entity.SPUser[] GetGroupMembers(string urlSite, string groupName);

        entity.SPGroup[] GetGroupsFromUser(string urlSite, string userLogin);

        void AddUserToGroup(string url, string login, string group);
        void RemoveUserFromGroup(string url, string login, string group);

        entity.SPList[] GetLists(string url);

        void RemoveUserFromSite(string p1, string p2);
        void DeleteItem(SPDoclibLocation list, int itemid);

        //string ValidateWorkflow(string siteUrl,string contentsMarkup, string contentsRules, string contentsConfig,string flag);
        //string AssociateWorkflow(string weburl, string relativeurl, string version);
        entity.SPWeb GetWeb(string url);
        entity.SPPermission[] GetPermissions(string urlSite, bool recursive, bool lists,string listname);
        void RemovePermissions(string urlSite, string listname, string userlogin, string groupname);
        void AddPermissions(string urlSite, string listname, string userlogin, string groupname, entity.SPPermissionMask mask);
        void AddGroup(string urlSiteCollection, string groupName,string ownerLogin, string ownerGroup, string description);
        void RemoveGroup(string urlSiteCollection, string groupName);
        void UpdateUserInformation(string sitecollectionurl, string login, string displayname, string email, string notes);
        entity.SPUser GetSiteUser(string sitecollectionurl, string login);

    }
}
